package com.cskaoyan.service.promote;


import com.cskaoyan.bean.common.BasePageInfoAdList;
import com.cskaoyan.bean.po.MarketAd;
import com.cskaoyan.mapper.MarketAdMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @BelongsProject: market-project
 * @BelongsPackage: com.cskaoyan.service.promote
 * @CreateTime: 2022-11-19  16:16
 * @Description: TODO
 * @Version: 1.0
 */
@Service
public class AdServiceImpl implements AdService {
    @Autowired
    MarketAdMapper marketAdMapper;

    @Override
    public PageInfo<MarketAd> selectMarketAdByBasePageInfo(BasePageInfoAdList in) {
        PageHelper.startPage(in.getPage(), in.getLimit());
        String content = in.getContent();
        String name = in.getName();
        if (content != null) {
            in.setContent(content.trim());
        }
        if (name != null) {
            in.setName(name.trim());
        }
        List<MarketAd> list = marketAdMapper.selectByBasePageInfoAdList(in);
        PageInfo<MarketAd> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public void deleteById(Integer id) {
        marketAdMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void updateMarketAd(MarketAd marketAd) {
        marketAdMapper.updateByPrimaryKeySelective(marketAd);
    }

    @Override
    public void insertByMarketAd(MarketAd marketAd) {
        marketAdMapper.insertSelective(marketAd);
    }
}